package com.zzw.basic.io;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;

public class WatchServiceTest {

	public static void main(String[] args){
		try {
			WatchService service = FileSystems.getDefault().newWatchService();
			Paths.get("C:/").register(service, StandardWatchEventKinds.ENTRY_CREATE,
					StandardWatchEventKinds.ENTRY_MODIFY,StandardWatchEventKinds.ENTRY_DELETE);
			while(true){
				WatchKey key = service.take();
				for(WatchEvent<?> event:key.pollEvents()){
					System.out.println(event.context() + "�ļ�������" + event.kind() + "�¼�!");
				}
				boolean valid = key.reset();
				if(!valid){
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
